$(document).ready(function() {
	$("#deleteemployee").live('click', function() {
		var employeeId = $(this).attr('employeeid');
		$.ajax({
			type : "GET",
			url : "employee",
			data : "action=deleteEmployee&employeeid=" + employeeId,
			success : function(response) {
				if (response == 1)
					$('tr[employee_row="' + employeeId + '"]').remove();
			}
		});
	});
	$("#add_stewardess").live('click',function(){
		$.ajax({
			type : "GET",
			url : "employee",
			data : "action=dialogEmployee",
			success : function(response) {
				$("#dialog_stewardess").html(response);
				$("#dialog_stewardess").dialog('open');
			}
		});
	});
	$("#editemployee").live('click',function(){
		var employeeId = $(this).attr('employeeid');
		$.ajax({
			type : "GET",
			url : "employee",
			data : "action=dialogEmployee&employeeid="+employeeId,
			success : function(response) {
				$("#dialog_stewardess").html(response);
				$("#dialog_stewardess").dialog('open');
			}
		});
//		$("#dialog_stewardess").dialog('open');
	});
	$("#btn_save_employee").live('click', function(){
		var id = $("[name=dialog_employee_id]").val();
		var name = $("[name=dialog_employee_name]").val();
		var gender = $("[name=dialog_employee_gender]").val();
		var age = $("[name=dialog_employee_age]").val();
		var rank = $("[name=dialog_employee_rank]").val();
		var lan = [];
		$("[name=dialog_employee_language] :selected").each(function(i, selected){
			lan[i] = $(selected).val();
		});
		var month = $("[name=dialog_employee_month_flight]").val();
		var total = $("[name=dialog_employee_total_flight]").val();
		var pass_exdate = $("[name=dialog_employee_exdate]").val();
		var pass_no = $("[name=dialog_employee_passno]").val();
		var category = $("[name=dialog_employee_category]").val();
		
		//ajax data
		var data_id = (id.length!=0)?("&employeeid="+id):"";
		var data_name = "&name="+name;
		var data_gender = "&gender="+gender;
		var data_age = "&age="+age;
		var data_rank = "&rank="+rank;
		var data_lan = "";
		for (var i in lan){
			data_lan +=("&lan"+i+"="+lan[i]);
		}
		var data_month = "&month="+month;
		var data_total = "&total="+total;
		var data_pass_exdate = "&passexdate="+pass_exdate;
		var data_passno = "&passno="+pass_no;
		var data_category = "&category="+category;
		var data = "action=saveEmployee" + 
					data_id + 
					data_name + 
					data_gender + 
					data_age + 
					data_rank + 
					data_lan + 
					data_month + 
					data_total + 
					data_pass_exdate + 
					data_passno + 
					data_category;
		//ajax
		$.ajax({
			type : "GET",
			url : "employee",
			data : data,
			success : function(response) {
				if (response != 0){
					if (id.length == 0){
						$("#list_container").html(response);
					}else{
						$('tr[employee_row="' + id + '"]').html(response);
					}
					$("#dialog_stewardess").dialog('close');
				}
			}
		});
	});
	$("#btn_cancel_employee").live('click', function(){
		$("#dialog_stewardess").dialog('close');
	});
});